package com.ruoyi.web.controller.kiku;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.kiku.domain.KikuDataStatistics;
import com.ruoyi.kiku.domain.KikuWeiboDetail;
import com.ruoyi.kiku.domain.pojo.DzStatistics;
import com.ruoyi.kiku.domain.pojo.FxStatistics;
import com.ruoyi.kiku.domain.pojo.ZfStatistics;
import com.ruoyi.kiku.service.IKikuWeiboDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * @author TT
 * @date 2025/4/2 10:26
 * @description 数据统计
 */
@RestController
@RequestMapping("/kiku/dataStatistics")
public class KikuDataStatisticsController {
    @Autowired
    private IKikuWeiboDetailService kikuWeiboDetailService;
    /**
     * 查询小鞠微博详情列表
     */
    @PreAuthorize("@ss.hasPermi('kiku:weiboDetail:list')")
    @GetMapping
    public AjaxResult dataStatistics()
    {
        List<KikuWeiboDetail> list = kikuWeiboDetailService.selectKikuWeiboDetailList(null);
        KikuDataStatistics dataStatistic =new KikuDataStatistics();
        List<DzStatistics> dzStatistics = new ArrayList<>();
        List<ZfStatistics> zfStatistics =new ArrayList<>();
        List<FxStatistics> fxStatistics = new ArrayList<>();
        List<Integer> dzStatisticsList = new ArrayList<>();
        List<Integer> fxStatisticsList = new ArrayList<>();
        List<Integer> zfStatisticsList = new ArrayList<>();
        //统计点赞数小于10万的微博数
        int dzXy10w = 0;
        //统计点赞数大于10万的微博数小于50万
        int dzXy50wDy10w = 0;
        //统计点赞数大于50万的微博数小于100万
        int dzXy100wDy50w = 0;
        //统计点赞数大于100万的微博数
        int dzDy100w = 0;
        //统计转发数小于10万的微博数
        int zfXy10w = 0;
        //统计转发数大于10万的微博数小于50万
        int zfXy50wDy10w = 0;
        //统计转发数大于50万的微博数小于100万
        int zfXy100wDy50w = 0;
        //统计转发数大于100万的微博数
        int zfDy100w = 0;
        //统计评论数小于10万的微博数
        int plXy10w = 0;
        //统计评论数大于10万的微博数小于50万
        int plXy50wDy10w = 0;
        //统计评论数大于50万的微博数小于100万
        int plXy100wDy50w = 0;
        //统计评论数大于100万的微博数
        int plDy100w = 0;
        for (int i = 0; i < list.size(); i++) {
            KikuWeiboDetail weiboData = list.get(i);
            if (weiboData.getLikeCount()<100000){
                dzXy10w++;
            }
            if (weiboData.getLikeCount()>100000 && weiboData.getLikeCount()<500000){
                dzXy50wDy10w++;
            }
            if (weiboData.getLikeCount()>500000 && weiboData.getLikeCount()<1000000){
                dzXy100wDy50w++;
            }
            if (weiboData.getLikeCount()>1000000){
                dzDy100w++;
            }
            if (weiboData.getCommentCount()<100000){
                zfXy10w++;
            }
            if (weiboData.getCommentCount()>100000 && weiboData.getCommentCount()<500000){
                zfXy50wDy10w++;
            }
            if (weiboData.getCommentCount()>500000 && weiboData.getCommentCount()<1000000){
                zfXy100wDy50w++;
            }
            if (weiboData.getCommentCount()>1000000){
                zfDy100w++;
            }
            if (weiboData.getRepostCount()<100000){
                plXy10w++;
            }
            if (weiboData.getRepostCount()>100000 && weiboData.getRepostCount()<500000){
                plXy50wDy10w++;
            }
            if (weiboData.getRepostCount()>500000 && weiboData.getRepostCount()<1000000){
                plXy100wDy50w++;
            }
            if (weiboData.getRepostCount()>1000000){
                plDy100w++;
            }
        }
        dzStatisticsList.add(dzDy100w);
        dzStatisticsList.add(dzXy100wDy50w);
        dzStatisticsList.add(dzXy50wDy10w);
        dzStatisticsList.add(dzXy10w);
        dataStatistic.setDzStatisticsList(dzStatisticsList);

        fxStatisticsList.add(zfDy100w);
        fxStatisticsList.add(zfXy100wDy50w);
        fxStatisticsList.add(zfXy50wDy10w);
        fxStatisticsList.add(zfXy10w);
        dataStatistic.setFxStatisticsList(fxStatisticsList);

        zfStatisticsList.add(plDy100w);
        zfStatisticsList.add(plXy100wDy50w);
        zfStatisticsList.add(plXy50wDy10w);
        zfStatisticsList.add(plXy10w);
        dataStatistic.setZfStatisticsList(zfStatisticsList);

        DzStatistics dz1 = new DzStatistics();
        dz1.setName("点赞数小于10万");
        dz1.setValue(dzXy10w);
        dzStatistics.add(dz1);

        DzStatistics dz2 = new DzStatistics();
        dz2.setName("点赞数大于10万小于50万");
        dz2.setValue(dzXy50wDy10w);
        dzStatistics.add(dz2);

        DzStatistics dz3 = new DzStatistics();
        dz3.setName("点赞数大于50万小于100万");
        dz3.setValue(dzXy100wDy50w);
        dzStatistics.add(dz3);

        DzStatistics dz4 = new DzStatistics();
        dz4.setName("点赞数大于100万");
        dz4.setValue(dzDy100w);
        dzStatistics.add(dz4);
        dataStatistic.setDzStatistics(dzStatistics);
        FxStatistics fx1 = new FxStatistics();
        fx1.setName("分享数小于10万");
        fx1.setValue(zfXy10w);
        fxStatistics.add(fx1);
        FxStatistics fx2 = new FxStatistics();
        fx2.setName("分享数大于10万小于50万");
        fx2.setValue(zfXy50wDy10w);
        fxStatistics.add(fx2);
        FxStatistics fx3 = new FxStatistics();
        fx3.setName("分享数大于50万小于100万");
        fx3.setValue(zfXy100wDy50w);
        fxStatistics.add(fx3);
        FxStatistics fx4 = new FxStatistics();
        fx4.setName("分享数大于100万");
        fx4.setValue(zfDy100w);
        fxStatistics.add(fx4);
        dataStatistic.setFxStatistics(fxStatistics);
        ZfStatistics zf1 = new ZfStatistics();
        zf1.setName("转发数小于10万");
        zf1.setValue(plXy10w);
        zfStatistics.add(zf1);
        ZfStatistics zf2 = new ZfStatistics();
        zf2.setName("转发数大于10万小于50万");
        zf2.setValue(plXy50wDy10w);
        zfStatistics.add(zf2);
        ZfStatistics zf3 = new ZfStatistics();
        zf3.setName("转发数大于50万小于100万");
        zf3.setValue(plXy100wDy50w);
        zfStatistics.add(zf3);
        ZfStatistics zf4 = new ZfStatistics();
        zf4.setName("转发数大于100万");
        zf4.setValue(plDy100w);
        zfStatistics.add(zf4);
        dataStatistic.setZfStatistics(zfStatistics);
        return success(dataStatistic);
    }
}
